added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSClassLibrary / CSSimpleObject.cs
blobd29bc0c8c51146cfed46dee4fde1ecd4504c4201
1 /****************************** Module Header ******************************\
2 Module Name: CSSimpleObject.cs
3 Project: CSClassLibrary
4 Copyright (c) Microsoft Corporation.
6 The code sample demonstrates a C# class library that we can use in other
7 applications. The class library exposes a simple class named CSSimpleObject.
8 The process of creating the class library is very straight-forward.
10 This source is subject to the Microsoft Public License.
11 See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
12 All other rights reserved.
14 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
15 EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
17 \***************************************************************************/
19 #region Using directives
20 using System;
21 using System.Diagnostics;
22 #endregion
25 namespace CSClassLibrary
27 public class CSSimpleObject
29 /// <summary>
30 /// Constructor
31 /// </summary>
32 public CSSimpleObject()
36 private float fField = 0F;
38 /// <summary>
39 /// This is a public Property. It allows you to get and set the value
40 /// of a float field.
41 /// </summary>
42 public float FloatProperty
44 get { return fField; }
45 set
47 // Fire the event FloatPropertyChanging
48 bool cancel = false;
49 if (FloatPropertyChanging != null)
51 FloatPropertyChanging(value, out cancel);
54 // If the change is not canceled, make the change.
55 if (!cancel)
57 fField = value;
62 /// <summary>
63 /// Returns a String that represents the current Object. Here, we
64 /// return the string form of the float field fField.
65 /// </summary>
66 /// <returns>the string form of the float field fField.</returns>
67 public override string ToString()
69 return this.fField.ToString("F2");
72 /// <summary>
73 /// This is a public static method. It returns the number of
74 /// characters in a string.
75 /// </summary>
76 /// <param name="str">a string</param>
77 /// <returns>the number of characters in the string</returns>
78 public static int GetStringLength(string str)
80 return str.Length;
83 /// <summary>
84 /// This is an event. The event is fired when the float property is
85 /// set.
86 /// </summary>
87 public event PropertyChangingEventHandler FloatPropertyChanging;
91 /// <summary>
92 /// Property value changing event handler
93 /// </summary>
94 /// <param name="NewValue">the new value of the property</param>
95 /// <param name="Cancel">
96 /// Output whether the change should be cancelled or not.
97 /// </param>
98 public delegate void PropertyChangingEventHandler(object NewValue, out bool Cancel);